import 'package:flutter/material.dart';
import 'package:flutter_app/util/DataUtil.dart';

import '../layout_widget/AlignCenterWidget.dart';
import '../layout_widget/FlexWidget.dart';
import '../layout_widget/RowColumnWidget.dart';
import '../layout_widget/StackPositionedWidget.dart';
import '../layout_widget/WrapFlowWidget.dart';
import 'ClipWidget.dart';
import 'ConstrainedWidget.dart';
import 'ContainerWidget.dart';
import 'DecoratedBoxWidget.dart';
import 'PaddingWidget.dart';
import 'ScaffoldTabBarWidget.dart';
import 'ScaffoldTabBarWidget2.dart';

/**
 * 容器类组件
 */
class ContainerListWidget extends StatelessWidget {
  ContainerListWidget({
    Key ?key,
    @required this.text, // 接收一个text参数
  }) : super(key: key);
  final String ?text;

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: AppBar(
        title: Text(text??""),
      ),
      body: BaseListPage(),
    );
  }
}

class BaseListPage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<BaseListPage> {
  var list = DataUtil.getContainerTitle();

  @override
  Widget build(BuildContext context) {
    return ListView.builder(
      itemCount: list.length,
      itemBuilder: _buildItem,
      itemExtent: 60,
    );
  }
}

Widget _buildItem(BuildContext context, int index) {
  var list = DataUtil.getContainerTitle();
  return Container(
    height: double.infinity,
    color: Colors.white,
    child: GestureDetector(
      child: Container(
        margin: EdgeInsets.all(10),
        padding: EdgeInsets.all(10),
        color: Colors.cyan,
        child: Text(
          list[index],
          style: TextStyle(
            color: Colors.white,
          ),
        ),
      ),
      onTap: () {
        toArount(index, context);
      },
    ),
  );
}

void toArount(int index, BuildContext context) {
  switch (index) {
    case 0:
      goTo(context, PaddingWidget(text: "填充[Padding]"));
      break;
    case 1:
      goTo(context, ConstrainedWidget(text: "尺寸限制类容器[]"));
      break;
    case 2:
      goTo(context, DecoratedBoxWidget(text: "装饰容器[DecoratedBox]"));
      break;
    case 3:
      goTo(context, ContainerWidget(text: "Container容器"));
      break;
    case 4:
      goTo(context, ScaffoldTabBarWidget(text: "Scaffold、TabBar、底部导航1"));
      break;
    case 5:
      goTo(context, ScaffoldTabBarWidget2(text: "Scaffold、TabBar、底部导航2"));
      break;
    case 6:
      goTo(context, ClipWidget(text: "Clip[裁剪]"));
      break;
  }
}

void goTo(BuildContext context, Widget widget) {
  Navigator.push(context, MaterialPageRoute(builder: (context) {
    return widget;
  }));
}
